package com.myteam.fugaocrm.base;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;

@ContextConfiguration({ "classpath*:spring.xml", "classpath*:springmvc.xml" })
@WebAppConfiguration("src/test/java")
@Transactional
@Rollback
public abstract class UnitTestSupport extends AbstractTestNGSpringContextTests {

    protected MockMvc mockMvc;
    protected MockHttpServletRequest mockRequest;
    protected MockHttpServletResponse mockResponse;
    protected MockHttpSession mockSession;
    
    @Resource
    protected WebApplicationContext webApplicationContext;

    @PostConstruct
    public void afterContextInit() {
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
        mockRequest = new MockHttpServletRequest();
        mockRequest.setCharacterEncoding("UTF-8");
        mockResponse = new MockHttpServletResponse();
        mockResponse.setCharacterEncoding("UTF-8");
    }
}
